package com.optimize_02.service.impl;

import com.optimize_02.WeatherData;
import com.optimize_02.service.DisplayElement;

import java.util.Observable;
import java.util.Observer;

public class ForecastDisplay implements Observer, DisplayElement {

    // Observable observable;
    private float currentPressure = 29.92f;
    private float lastPressure;

    public ForecastDisplay(Observable observable) {
        // this.observable = observable;
        observable.addObserver(this);
    }

    @Override
    public void display() {
        System.out.println("lastPressure: " + lastPressure + "   currentPressure: " + currentPressure);
    }
    @Override
    public void update(Observable o, Object arg) {
        if (o instanceof WeatherData) {
            WeatherData weatherData = (WeatherData) o;
            lastPressure = currentPressure;
            currentPressure = weatherData.getPressure();
        }
        display();
    }
}
